package com.newopenlab.hmc.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class LinesExtractor {
	
	public File inputFile=null;
	
	public List<Integer> getHandDelimeters(List<String> rows){
		List<Integer> delimeters=new ArrayList<Integer>();
		for(int i=0;i<rows.size();i++){
			if(rows.get(i).contains(BasicParser.HEADER_HAND_PRE)){
				delimeters.add(i);
			}
		}
		return delimeters;
	}
	
	public List<Integer> getHandPreflopDelineters(List<String> rows){
		List<Integer> delimeters=new ArrayList<Integer>();
		for(int i=0;i<rows.size();i++){
			if(rows.get(i).contains(BasicParser.HEADER_PREFLOP_PRE)){
				delimeters.add(i);
			}
		}
		return delimeters;
	}
	
	public List<Integer> getHandFlopDelineters(List<String> rows){
		List<Integer> delimeters=new ArrayList<Integer>();
		for(int i=0;i<rows.size();i++){
			if(rows.get(i).contains(BasicParser.HEADER_WAY_FLOP_PRE)){
				delimeters.add(i);
			}
		}
		return delimeters;
	}
	
	public List<Integer> getHandRiverDelineters(List<String> rows){
		List<Integer> delimeters=new ArrayList<Integer>();
		for(int i=0;i<rows.size();i++){
			if(rows.get(i).contains(BasicParser.HEADER_WAY_RIVER_PRE)){
				delimeters.add(i);
			}
		}
		return delimeters;
	}
	
	public List<Integer> getHandTurnDelineters(List<String> rows){
		List<Integer> delimeters=new ArrayList<Integer>();
		for(int i=0;i<rows.size();i++){
			if(rows.get(i).contains(BasicParser.HEADER_WAY_TURN_PRE)){
				delimeters.add(i);
			}
		}
		return delimeters;
	}
	
	public List<Integer> getSummaryDelineters(List<String> rows){
		List<Integer> delimeters=new ArrayList<Integer>();
		for(int i=0;i<rows.size();i++){
			if(rows.get(i).contains(BasicParser.HEADER_SUMMARY_PRE)){
				delimeters.add(i);
			}
		}
		return delimeters;
	}
	
	public List<String> extractN() throws IOException{
		List<String> res=null;
		res=new ArrayList<String>();
		FileInputStream fstream =null;
		fstream=new FileInputStream(this.inputFile);
		// Get the object of DataInputStream
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		//Read File Line By Line
		while ((strLine = br.readLine()) != null)   {
		  res.add(strLine);
		}
		  //Close the input stream
		in.close();
		
		return res;
	}
	
	public List<String> extract() throws IOException{
		List<String> res=null;
		res=new ArrayList<String>();
		FileInputStream fstream =null;
		fstream=new FileInputStream(this.inputFile);
		// Get the object of DataInputStream
		DataInputStream in = new DataInputStream(fstream);
		//Charset cs=Charset.forName("ISO-8859-15");
		Charset cs=Charset.forName("UTF-8");
		BufferedReader br = new BufferedReader(new InputStreamReader(in,cs));
		String strLine;
		//Read File Line By Line
		byte[] buf=null;
		while ((strLine = br.readLine()) != null)   {
		  res.add(strLine);
		}
		  //Close the input stream
		in.close();
		
		return res;
	}
}
